package edu.office.applicationRepository;

import edu.office.entities.Studentaccupoints;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;

import java.util.List;

/**
 *
 * @author hadoop
 */
@Named("studentaccupointsRepositoryA")
@ApplicationScoped
public class StudentaccupointsRepository extends ApplicationCommonRepository<Studentaccupoints>{


    //传入教师或学生，计算此学生的积分
    public double calculateStudentPoints(Integer studentId,boolean teacher) {
        String columnName="studentId";
        if(teacher)columnName="teacherId";
        //创建资源获得的积分与人家点赞获得的积分
        List<Studentaccupoints> curStuAllPoints = find(columnName,studentId).list();
        if (curStuAllPoints.isEmpty()) {
            return 0;
        } else {
            double allPoints = 0;
            allPoints = curStuAllPoints.stream().map(Studentaccupoints::getPOINTS_NUM).reduce(allPoints, Double::sum);
            return allPoints;
        }
    }


}
